

export function urlEncode(str){
    let res = encodeURIComponent(str);
    return res
}

export function urlDecode(str){
    let res = decodeURIComponent(str);
    return res
}


var Terminal = {
    // 辨别移动终端类型
    platform : function(){
    var ua = navigator.userAgent.toLowerCase();
    var u = navigator.userAgent, app = navigator.appVersion;
    document.write(u);
    return {
        // android终端或者uc浏览器
        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
        // 是否为iPhone或者QQHD浏览器
        iPhone: u.indexOf('iPhone') > -1 ,
        android_weixin: ua.match(/MicroMessenger/i) == 'micromessenger' && u.indexOf('Android')>-1 ,
        iphone_weixin: ua.match(/MicroMessenger/i) == 'micromessenger' && u.indexOf('iPhone')>-1 ,
        android_qq:ua.match(/QQ/i) == "qq" && u.indexOf('Android')>-1 ,
        iphone_qq:ua.match(/QQ/i) == "qq" && u.indexOf('iPhone')>-1 ,
        // 是否iPad
        iPad: u.indexOf('iPad') > -1
        };
    }
}

export function agentCheck(Url){
    

    // 辨别移动终端的语言：zh-cn、en-us、ko-kr、ja-jp...
    language : (navigator.browserLanguage || navigator.language).toLowerCase()
    var theUrl = 'http://www.myfont.me';
    if(Terminal.platform.iPhone){
        loadStyleText(cssText);
        location.href = Url;
        return "ipwechat"
    } else if(Terminal.platform.android_weixin){
        loadHtml();
        loadStyleText(cssText);
        // theUrl = 'http://www.myfont.me';
    } else if(Terminal.platform.iphone_weixin){
        loadStyleText(cssText);
        theUrl = "itms-services://?action=download-manifest&url=https://hwdev.xiezixiansheng.com:8010/qrimg/f193bfc8d1f564dddf55563391c0839a_ios_9.0e4be2c5ca523891a103b21e5825a0154.plist";
        location.href = theUrl;
    }else if (Terminal.platform.android_qq){
        loadStyleText(cssText);
        theUrl = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.handwriting.makefont&channel=0002160650432d595942&fromcase=60001';
        location.href = theUrl;
    }else if (Terminal.platform.iphone_qq){
        loadStyleText(cssText);
        theUrl = "itms-services://?action=download-manifest&url=https://hwdev.xiezixiansheng.com:8010/qrimg/f193bfc8d1f564dddf55563391c0839a_ios_9.0e4be2c5ca523891a103b21e5825a0154.plist";
        location.href = theUrl;
    }else if(Terminal.platform.android){
        loadStyleText(cssText);

        theUrl = 'http://wxz.myapp.com/16891/1F359CFAEE8F62F5ECC5F1B7FCAE61B2.apk?fsname=com.handwriting.makefont_3.7.0_26.apk&hsr=4d5s';
        location.href = theUrl;
    }
    else if(Terminal.platform.iPad){
        // 还可以通过language，区分开多国语言版
        switch(Terminal.language){
            case 'en-us':
                theUrl = '你的iPad APP（英文版）对应下载地址：APP Store地址';
                break;
            case 'ko-kr':
                theUrl = '你的iPad APP（韩语版）对应下载地址：APP Store地址';
                break;
            case 'ja-jp':
                theUrl = '你的iPad APP（日文版）对应下载地址：APP Store地址';
                break;
            default:
                theUrl = '你的iPad APP（中文版-默认）对应下载地址：APP Store地址';
            }
    }else{
        // theUrl = 'http://www.myfont.me';
        // location.href = theUrl;;
        return "pc"
    }
}//agentCheck